﻿Option Explicit On
Imports System.Data
Imports System.Text
Imports Global_Visas_Business_Layer

Partial Public Class frmWebLogin
    Public PersonId As Long
    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnGenerate.Click
        Dim SQL As New StringBuilder
        Dim dtPerson As New DataTable
        Dim myPerson As PrivateIndividual.PersonInfo

        If MsgBox("Generating a new password will prevent the client from using the website until you send them the new password, are you sure you want to proceed?", vbYesNo + vbExclamation, "Confirm password reset") <> MsgBoxResult.Yes Then
            Exit Sub
        End If

        People.GenerateWebPassword(Me.PersonId)
        myPerson = PrivateIndividual.GetPerson(Me.PersonId)
        Me.txtUsername.Text = myPerson.WebUserName
        Me.txtPassword.Text = myPerson.WebPassword
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub frmWebLogin_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            btnClose_Click(sender, e)
        End If
    End Sub

    Private Sub frmWebLogin_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        If Me.PersonId = 0 Then
            CommonFuncs.DisplayMessage("Person Not Set", CommonDialog.CustomDialogIcons.Information, "Error")
            Me.Close()
            Exit Sub
        End If

        Dim myPerson As PrivateIndividual.PersonInfo = PrivateIndividual.GetPerson(Me.PersonId)

        Me.txtUsername.Text = myPerson.WebUserName
        Me.txtPassword.Text = myPerson.WebPassword

    End Sub
End Class
